import Vue from 'vue'
import Router from 'vue-router'
import Home from './pages/home'
import Index from './pages/index'
import ProductList from './pages/ProductList'
import cart from './pages/cart'
import productDetail from './pages/productDetail'
import userAddress from './pages/userAddress'
import orderList from './pages/orderList'

const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
	if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
	return originalPush.call(this, location).catch(err => err)
}

Vue.use(Router);

const routesMap = [
	{
		path: '/',
		name: 'home',
		component: Home,
		redirect: '/index',
		children: [
			{
				path: '/index',
				name: 'index',
				component: Index,
			},
			{
				path: '/productList',
				name: 'productList',
				component: ProductList,
			},
			{
				path: '/cart',
				name: 'cart',
				component: cart,
			},
			{
				path: '/productDetail',
				name: 'productDetail',
				component: productDetail,
			},
			{
				path: '/userAddress',
				name: 'userAddress',
				component: userAddress,
			},
			{
				path: '/orderList',
				name: 'orderList',
				component: orderList,
			},
		]
	},
	{
		path: '/login',
		name: 'login',
		component: () => import('./pages/login.vue')
	},
	{
		path: '/applylicense',
		component: () => import('./pages/applylicense.vue'),
		hidden: true
	},
]



//路由守卫
const createRouter = () => new Router({

	scrollBehavior: () => ({
		y: 0
	}),
	routes: routesMap
})
const router = createRouter()

// });
export default router;
